/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frm_JInterFrameQuanLyPhim.java
 *
 * Created on Aug 2, 2011, 5:52:07 PM
 */
package GUI;

import DAO.PhimDAO;
import DAO.TheLoaiPhimDAO;
import POJO.PhimPOJO;
import POJO.TheLoaiPhimPOJO;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author HP
 */
public class frm_JInterFrameQuanLyPhim extends javax.swing.JInternalFrame {

    /**
     * Creates new form frm_JInterFrameQuanLyPhim
     */
    ArrayList<TheLoaiPhimPOJO> dstheloai = new ArrayList<TheLoaiPhimPOJO>();
    TheLoaiPhimDAO loaiphimDAO = new TheLoaiPhimDAO();
    PhimDAO phimDAO = new PhimDAO();
    ArrayList<PhimPOJO> dsPhim = null;
    DefaultTableModel dftablemodel = new DefaultTableModel();//Doi tuong thao tac dong cot cua table
    private String arr_trash[] = {"Không hoạt động", "Hoạt động"};
    int stt = 1;

    /**
     * Ham Khoi Tao Cac Cot Cho jtblDSPhim
     */
    private void InitColumTable() {
        dftablemodel.addColumn("STT");
        dftablemodel.addColumn("MaPhim");
        dftablemodel.addColumn("Tên Phim");
        dftablemodel.addColumn("Loại Phim");
        dftablemodel.addColumn("Tóm Tắt");
        dftablemodel.addColumn("Thời lượng");
        dftablemodel.addColumn("Tình Trạng");
        this.jtblDSPhim.setModel(dftablemodel);
    }

    /**
     * Ham Khoi Tao cua Form (Khi run thi ham nay dc chay dau tien)
     */
    public frm_JInterFrameQuanLyPhim() {
        initComponents();
        InitColumTable();
        this.setResizable(false);
        
        jcmbTinhTrang.removeAllItems();
        for(String tt : arr_trash){
            jcmbTinhTrang.addItem(tt);
        }
    }

    /**
     * Ham Khoi Tao Cac Gia Tri Cho Combobox
     */
    private void Init() {
        try {
            DefaultComboBoxModel dfcbxTheLoai = new DefaultComboBoxModel();

            dstheloai = loaiphimDAO.layDanhTheLoaiPhimCacMaTheLoaiPhim();

            for (TheLoaiPhimPOJO i : dstheloai) {
                Vector vt = new Vector();
                vt.add(i.getMaTheLoaiPhim());
                vt.add(i.getTenTheLoaiPhim());
                //them mot dong voao model
                dfcbxTheLoai.addElement(vt);
            }
            this.jcmbTheLoai.setModel(dfcbxTheLoai);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * Ham Xoa Cac Dong Trong table ( quan trong lam do) Muc dich: trong table
     * co nhieu dong trong do,muon khoi tao lai cac gia tri table moi hoan toan
     * thi phai su dung ham nay de xoa tat ca cac dong hien co trong table
     */
    public void ClearTableDSPhim() {
        javax.swing.table.DefaultTableModel mode = (DefaultTableModel) this.jtblDSPhim.getModel();

        for (int i = jtblDSPhim.getRowCount() - 1; i >= 0; i--) {
            mode.removeRow(i);
//
        }
    }

    private void HienThiDanhPhimPhim() {
        dsPhim = phimDAO.layDanhPhimCacMaPhim();
//        ClearTableDSPhim();
        // InitColumTable();
        // jtblDSPhim.removeAll();
        // DefaultTableModel mode=new DefaultTableModel();

        javax.swing.table.DefaultTableModel model = (DefaultTableModel) this.jtblDSPhim.getModel();
        stt = 1;
        for (PhimPOJO i : dsPhim) {
            Vector vt = new Vector();
            vt.add(stt);
            vt.add(i.getMaPhim());
            vt.add(i.getTenPhim());
            String tenloaiPhim ="";
            for(TheLoaiPhimPOJO tl : dstheloai){
                if(i.getLoaiPhim()==tl.getMaTheLoaiPhim()){
                    tenloaiPhim = tl.getTenTheLoaiPhim();
                    break;
                }
            }
            vt.add(tenloaiPhim);
            vt.add(i.getTomTat());
            vt.add(i.getThoiLuong());
            vt.add(arr_trash[i.getTrangThai()]);
            model.addRow(vt);
            stt++;
        }
        this.jtblDSPhim.setModel(dftablemodel);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jpnThongTinQuanLySach = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jcmbTheLoai = new javax.swing.JComboBox();
        jtxtThoiLuong = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtxtTenPhim = new javax.swing.JTextField();
        jbtnSuaSach = new javax.swing.JButton();
        jbtnThemSach = new javax.swing.JButton();
        jbtnXoaSach = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtxtTomTat = new javax.swing.JTextPane();
        jcmbTinhTrang = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblDSPhim = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setResizable(true);
        setTitle("Quản lý phim");
        setDoubleBuffered(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 204, 204));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel8.setText("QUẢN LÝ PHIM ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(316, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addGap(297, 297, 297))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpnThongTinQuanLySach.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255), 2), "Thông tin phim", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Tóm tắt");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Thể loại phim");

        jcmbTheLoai.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jcmbTheLoai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbTheLoaiActionPerformed(evt);
            }
        });

        jtxtThoiLuong.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Thời lượng");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Tình trạng phim");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel7.setText("Tên phim");

        jtxtTenPhim.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jbtnSuaSach.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbtnSuaSach.setText("Sửa");
        jbtnSuaSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSuaSachActionPerformed(evt);
            }
        });

        jbtnThemSach.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbtnThemSach.setText("Thêm");
        jbtnThemSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemSachActionPerformed(evt);
            }
        });

        jbtnXoaSach.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbtnXoaSach.setText("Xóa");
        jbtnXoaSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXoaSachActionPerformed(evt);
            }
        });

        jScrollPane3.setViewportView(jtxtTomTat);

        jcmbTinhTrang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcmbTheLoai, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jtxtThoiLuong)
                            .addComponent(jtxtTenPhim)
                            .addComponent(jScrollPane3)
                            .addComponent(jcmbTinhTrang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap(57, Short.MAX_VALUE)
                        .addComponent(jbtnThemSach, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnXoaSach, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnSuaSach, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(24, 24, 24))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jcmbTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtTenPhim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel3))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtThoiLuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jcmbTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(jbtnXoaSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnSuaSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnThemSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(53, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jpnThongTinQuanLySachLayout = new javax.swing.GroupLayout(jpnThongTinQuanLySach);
        jpnThongTinQuanLySach.setLayout(jpnThongTinQuanLySachLayout);
        jpnThongTinQuanLySachLayout.setHorizontalGroup(
            jpnThongTinQuanLySachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnThongTinQuanLySachLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jpnThongTinQuanLySachLayout.setVerticalGroup(
            jpnThongTinQuanLySachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnThongTinQuanLySachLayout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 51, 255), 2), "Danh sách phim", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jtblDSPhim.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtblDSPhim.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblDSPhimMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtblDSPhim);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jpnThongTinQuanLySach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnThongTinQuanLySach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnThemSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemSachActionPerformed
        // TODO add your handling code here:
//        try{
//            Vector vtnxb=(Vector) this.jcmbxNhaXuatBan.getSelectedItem();
//            Vector vttheloai=(Vector) this.jcmbTheLoai.getSelectedItem();
//            int matheloai=(Integer)vttheloai.get(0);
//            String manbx=(String) vtnxb.get(0);
//
//            PhimPOJO Phimdto=new PhimPOJO();
//
//            Phimdto.setMaNhaXuatBan(manbx);
//            Phimdto.setMaTheLoai(matheloai);
//            Phimdto.setMaPhim(this.jtxtMaPhim.getText());
//            Phimdto.setTenPhim(this.jtxtTenPhim.getText());
//            Phimdto.setSoLuongTon(Integer.parseInt(this.jtxtSoLuongTon.getText()));
//            Phimdto.setGiaBan(Float.parseFloat(this.jtxtGiaBan.getText()));
//
//            if(Phimdao.themPhim(Phimdto)==true)
//            {
//               Vector vt=new Vector();
//               vt.add(stt++);
//               vt.add(Phimdto.getMaPhim());
//               vt.add(Phimdto.getTenPhim());
//               vt.add(Phimdto.getSoLuongTon());
//               vt.add(Phimdto.getGiaBan());
//               this.dftablemodel.addRow(vt);
//            }
//
//        }catch(Exception ex)
//        {
//             JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
//        }
    }//GEN-LAST:event_jbtnThemSachActionPerformed

    private void jcmbTheLoaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbTheLoaiActionPerformed
        // TODO add your handling code here:
        try {
//            this.HienThiDanhPhimPhim();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jcmbTheLoaiActionPerformed

   /**
     * Ham jbtnXoaPhimActionPerformed xoa Phim theo ma Phim
     *
     * @param evt
     */
    private void jbtnXoaSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaSachActionPerformed
        // TODO add your handling code here:
//        try
//        {
//           String maPhim= this.jtxtMaPhim.getText();
//           if(Phimdao.xoaPhim(maPhim))
//           {
//                JOptionPane.showMessageDialog(this,"Xóa sách thành công", "Thống báo",JOptionPane.DEFAULT_OPTION);
//                HienThiDanhPhimPhim();
//                this.jtxtMaPhim.setText("");
//                this.jtxtTenPhim.setText("");
//                this.jtxtGiaBan.setText("");
//                this.jtxtSoLuongTon.setText("");
//           }
//        }catch(Exception ex)
//        {
//              JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
//        }
    }//GEN-LAST:event_jbtnXoaSachActionPerformed

    private void jbtnSuaSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaSachActionPerformed
        // TODO add your handling code here:
//        try
//        {
//            Vector vtnxb=(Vector) this.jcmbxNhaXuatBan.getSelectedItem();
//            Vector vttheloai=(Vector) this.jcmbTheLoai.getSelectedItem();
//            int matheloai=(Integer)vttheloai.get(0);
//            String manbx=(String) vtnxb.get(0);
//
//             PhimPOJO Phimdto=new PhimPOJO();
//
//            Phimdto.setMaNhaXuatBan(manbx);
//            Phimdto.setMaTheLoai(matheloai);
//            Phimdto.setMaPhim(this.jtxtMaPhim.getText());
//            Phimdto.setTenPhim(this.jtxtTenPhim.getText());
//            Phimdto.setSoLuongTon(Integer.parseInt(this.jtxtSoLuongTon.getText()));
//            Phimdto.setGiaBan(Float.parseFloat(this.jtxtGiaBan.getText()));
//
//            if(Phimdao.capNhatPhim(Phimdto))
//            {
//                JOptionPane.showMessageDialog(this,"Cập nhật thành công", "Thống báo",JOptionPane.DEFAULT_OPTION);
//                HienThiDanhPhimPhim();
//            }
//
//        }catch(Exception ex)
//        {
//         JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
//        }
    }//GEN-LAST:event_jbtnSuaSachActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
         try {
            Init();
            HienThiDanhPhimPhim();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_formInternalFrameOpened

    private void jtblDSPhimMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblDSPhimMouseClicked
        // TODO add your handling code here:
         try {
             int vt = -1;
             vt = this.jtblDSPhim.getSelectedRow();
             if(vt >= 0){
                 PhimPOJO ph = (PhimPOJO)dsPhim.get(vt);
                 this.jtxtTenPhim.setText(ph.getTenPhim());
            this.jtxtTomTat.setText(ph.getTomTat());
            this.jtxtThoiLuong.setText(""+ ph.getThoiLuong());
            
            int loaiphim = ph.getLoaiPhim();
            int trangthai = ph.getTrangThai();
            
            for(int j=0; j<dstheloai.size(); j++){
                TheLoaiPhimPOJO tlp = dstheloai.get(j);
                if(tlp.getMaTheLoaiPhim()==loaiphim){
                    jcmbTheLoai.setSelectedIndex(j);
                    break;
                }
            }
            
            jcmbTinhTrang.setSelectedIndex(trangthai);
////            this.jtblDSPhim.changeSelection(vt, 0, false, false);
////            int cl = this.jtblDSPhim.getSelectedColumn();
////            int maPhim = this.jtblDSPhim.getValueAt(vt, cl);
//           // String maPhim = (String) this.jtblDSPhim.getValueAt(vt, 1);
////            String tenPhim = (String) this.jtblDSPhim.getValueAt(vt, 2);
//            this.jtxtTenPhim.setText(this.jtblDSPhim.getValueAt(vt, 2).toString());
//            this.jtxtTomTat.setText(this.jtblDSPhim.getValueAt(vt, 4).toString());
//            int maTheLoai = (Integer) this.jtblDSPhim.getValueAt(vt, 3);
//           
////            this.jcmbTheLoai.setToolTipText(this.jtblDSPhim.getValueAt(vt,3).toString());
//            this.jtxtThoiLuong.setText(this.jtblDSPhim.getValueAt(vt, 5).toString());
//            this.jtxtTinhTrang.setText(this.jtblDSPhim.getValueAt(vt, 6).toString().trim());
//            String tenTheLoai = "";
////            ArrayList<TheLoaiPhimPOJO> loaiphimDAO= loaiphimDAO.layDanhTheLoaiPhimCacMaTheLoaiPhim();
//            for(int j=0; j<dstheloai.size(); j++){
//                if(maTheLoai == dstheloai.get(j).getMaTheLoaiPhim()){
//                    tenTheLoai = dstheloai.get(j).getTenTheLoaiPhim();
//                }
//            }
//            this.jcmbTheLoai.setSelectedItem(tenTheLoai);
        }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Đã xảy ra lỗi", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jtblDSPhimMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbtnSuaSach;
    private javax.swing.JButton jbtnThemSach;
    private javax.swing.JButton jbtnXoaSach;
    private javax.swing.JComboBox jcmbTheLoai;
    private javax.swing.JComboBox jcmbTinhTrang;
    private javax.swing.JPanel jpnThongTinQuanLySach;
    private javax.swing.JTable jtblDSPhim;
    private javax.swing.JTextField jtxtTenPhim;
    private javax.swing.JTextField jtxtThoiLuong;
    private javax.swing.JTextPane jtxtTomTat;
    // End of variables declaration//GEN-END:variables
}
